﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Net.Http.Headers;

namespace Domain
{
    public class NorthwindDbInitializerStratege : DropCreateDatabaseAlways<NorthwindDbContext>
    {
        protected override void Seed(NorthwindDbContext context)
        {

            var tom = new Customer { Name = "Tom" };
            var dick = new Customer { Name = "Dick" };
            var harry = new Customer { Name = "Harry" };
            var marry = new Customer { Name = "Marry" };
            var jay = new Customer { Name = "Jay" };
            tom.Purchases = new List<Purchase>
            {
                new Purchase {Date = new DateTime(2016, 1, 1), Description = "Bike", Price = 500m},
                new Purchase {Date = new DateTime(2016, 1, 2), Description = "Holidy", Price = 2000m}
            };
            dick.Purchases = new List<Purchase>
            {
                new Purchase {Customer=dick,Date = new DateTime(2017, 1, 3), Description = "Bike", Price = 600m,
                    PurchaseItems = new List<PurchaseItem>{
                        new PurchaseItem {Detail="Flight",Price=1500m },
                        new PurchaseItem {Detail="Accommodation",Price=500m },
                        new PurchaseItem {Detail="Camera",Price=400m },
                } },
                new Purchase {Date = new DateTime(2017, 1, 4), Description = "Phone", Price = 300m}
            };
            harry.Purchases = new List<Purchase>
            {
                new Purchase {Date = new DateTime(2017, 1, 5), Description = "Hat", Price = 50m}
            };
            marry.Purchases = new List<Purchase>
            {
                new Purchase {Date = new DateTime(2018, 1, 6), Description = "Car", Price = 15000m},
                new Purchase {Date = new DateTime(2018, 1, 7), Description = "Boat", Price = 30000m},
                new Purchase {Date = new DateTime(2018, 1, 8), Description = "Camera", Price = 1200m},
            };
            context.Customers.AddOrUpdate(tom);
            context.Customers.AddOrUpdate(dick);
            context.Customers.AddOrUpdate(harry);
            context.Customers.AddOrUpdate(marry);
            context.Customers.AddOrUpdate(jay);
            context.SaveChanges();
            var purchase = new Purchase { Date = new DateTime(2018, 1, 9), Description = "Jacket", Price = 80m };
            context.Purchases.AddOrUpdate(purchase);

            //insert MedicalArticles values(1, 'Influenza', '<this is the abstract...>')
            //insert MedicalArticles values(2, 'Diabetes', '<this is the abstract...>')

            context.MediaArticles.Add(new MediaArticle {Topic = "Influenza", Abstract = "<this is the abstract...>"});
            context.MediaArticles.Add(new MediaArticle { Topic = "Diabetes", Abstract = "<this is the abstract...>" });
            //insert Product values(1, 'Widget', 0, '2007-1-1')
            context.Products.AddOrUpdate(new Product
            {
                Description = "Widget",
                Discontinued = false,
                LastSale = new DateTime(2017, 1, 1)
            });
            base.Seed(context);
        }
    }
}